/**
 * 格式化获取时间
 * @param {Object} str
 * @param {Object} time
 */
function formatTime(str, time){
  var d = new Date();
  if(time){
    d = new Date(time * 1000);
  }
  
  str = str.replace(/Y/, d.getFullYear());
  str = str.replace(/m/, d.getMonth()>=9 ? d.getMonth() + 1 : '0' + (d.getMonth() + 1));
  str = str.replace(/d/, d.getDate() > 9 ? d.getDate() : '0' + d.getDate());
  
  str = str.replace(/H/, d.getHours() >9 ? d.getHours() : '0' + d.getHours());
  str = str.replace(/i/, d.getMinutes() >9 ? d.getMinutes() : '0' + d.getMinutes());
  str = str.replace(/s/, d.getSeconds() >9 ? d.getSeconds() : '0' + d.getSeconds());
  
  return str;
}

/**
 * 获取当前时间戳
 * @param {Object} flag
 */
function time(flag, time){
  var now = new Date();
  if(time){
    now = new Date(time);
  }
  
  if(flag){
    //flag 为真，输出毫秒时间
    return now.getTime();
  } else {
    return Math.floor(now.getTime()/1000);
  }
}

exports.formatTime = formatTime;
exports.time = time;